﻿@model Piedone.ContentTemplates.Models.TemplatePart
@using Orchard.ContentManagement;

@{
    Script.Require("jQuery").AtFoot();

    var templateItems = Model.AvailableTemplates.Select(item => new SelectListItem { Text = item.As<Orchard.ContentManagement.Aspects.ITitleAspect>().Title, Value = item.Id.ToString() });
}

@if (Model.AvailableTemplates.Any())
{
    <fieldset class="piedone-content-templates-initialisation-fieldset">
        <legend>@T("Initialise from template")</legend>
        <div>
            <ol>
                <li>
                    <label>@T("Select template")</label>
                    @Html.DropDownListFor(m => m.TemplateId, new SelectList(templateItems, "Value", "Text"))
                </li>
                <li>
                    <label>@T("Select what to load from the template")</label>
                    <ul>
                        @for (int i = 0; i < Model.TemplateLoaders.Count; i++)
                        {
                            var provider = Model.TemplateLoaders[i];
                            @Html.HiddenFor(m => m.TemplateLoaders[i].Name)
                            
                            <li>
                                @Html.CheckBoxFor(m => m.TemplateLoaders[i].IsSelected)
                                @provider.Descriptor.DisplayName - 
                                @provider.Descriptor.Description
                            </li>
                        }
                    </ul>
                </li>
            </ol>
            <span class="hint">@T("When you hit save the item will be loaded from the template's content. Beware that (depending on what you selected to load from the template) content from the template can overwrite the current content of this item.")</span>
        </div>
    </fieldset>

    using (Script.Foot())
    {
    <script type="text/javascript">
        (function ($) {
            $(".piedone-content-templates-initialisation-fieldset legend")
                .expandoControl(function (controller) { return controller.next("div"); }, { collapse: true, remember: false });
        })(jQuery);
    </script>
    }
}